package com.haoxin.ai_course.modules.course.controller.admin;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.haoxin.ai_course.common.annotation.SysLog;
import com.haoxin.ai_course.common.base.AbstractController;
import com.haoxin.ai_course.common.utils.HttpJsonResult;
import com.haoxin.ai_course.common.utils.R;
import com.haoxin.ai_course.modules.course.biz.AcCourseUserBusiness;
import com.haoxin.ai_course.modules.course.entity.AcCourseUser;
import com.haoxin.ai_course.modules.course.entity.VO.AcCourseUserVO;
import com.haoxin.ai_course.modules.course.entity.VO.AcCourseVO;
import com.haoxin.ai_course.modules.course.service.AcCourseUserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;



/**
 * 课程用户表
 * 
 * @author xingxiangguo
 * @email bugcn@qq.com
 * @date 2022-06-06 09:44:49
 */
@RestController
@AllArgsConstructor
@RequestMapping("/course/accourseuser")
@Api(value="api",tags="后台-课程用户管理")
public class AdminAcCourseUserController  extends AbstractController {
    private final  AcCourseUserService acCourseUserService;
    private final  AcCourseUserBusiness acCourseUserBusiness;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("course:accourseuser:list")
    public R list(@RequestParam Map<String, Object> params){
        //查询列表数据
        QueryWrapper<AcCourseUser> queryWrapper = new QueryWrapper<>();
        IPage<AcCourseUser> sysConfigList = acCourseUserService.page(mpPageConvert.<AcCourseUser>pageParamConvert(params),queryWrapper);
        return R.ok().put("page", mpPageConvert.pageValueConvert(sysConfigList));
    }

    /**
     * 全部列表
     */
    @GetMapping("/fullList")
    @ApiOperation("全部课程列表")
    public HttpJsonResult<List<AcCourseUserVO>> fullList(){
    	//查询列表数据
    	HttpJsonResult<List<AcCourseUserVO>>  result = new HttpJsonResult<List<AcCourseUserVO>> ();
    	try {
			result = acCourseUserBusiness.fullList(getUserId());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	return result;
    }
    
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("course:accourseuser:info")
    public R info(@PathVariable("id") Integer id){
        return R.ok().put("acCourseUser", acCourseUserService.getById(id));
    }


    /**
     * 新增课程用户表
     */
    @SysLog("新增课程用户表数据")
    @RequestMapping("/save")
    @RequiresPermissions("course:accourseuser:save")
    public R save(@RequestBody AcCourseUser acCourseUser){
        acCourseUserService.save(acCourseUser);
        return R.ok();
    }


    /**
     * 修改
     */
    @SysLog("修改课程用户表数据")
    @RequestMapping("/update")
    @RequiresPermissions("course:accourseuser:update")
    public R update(@RequestBody AcCourseUser acCourseUser){
		acCourseUserService.updateById(acCourseUser);
        return R.ok();
    }


    /**
     * 删除
     */
    @SysLog("删除课程用户表数据")
    @RequestMapping("/delete")
    @RequiresPermissions("course:accourseuser:delete")
    public R delete(@RequestBody Integer[] ids){
		acCourseUserService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }
	
}
